package main

import (
	"fmt"
	"strconv"
)

//带符号的整数反转
func reverse(x int) int {
	s := strconv.Itoa(x)
	new := ""
	if s == "0" {
		return 0
	}
	l := len(s)
	if s[0] == '-' {
		new += "-"
		l -= 1
		s = s[1:]
	}
	flag := 1
	for i := l - 1; i >= 0; i-- {
		if s[i] == '0' && flag <= 2 {
			//flag = true
			flag = 2
			continue
		} else {
			flag = 3
			new += string(s[i])
		}
	}
	a, _ := strconv.ParseInt(new, 10, 64)
	if a >= 2147483647 || a <= -2147483647 {
		return 0
	}
	return int(a)
}

func main() {
	a := reverse(-120300)
	fmt.Println(a)
}
